home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4729 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Asynchronous I/O, Re: cin.get() function challenge
  5. Date: 31 Jan 1996 22:02:32 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan31170232@g7240065.bridge.bst.bls.com>
  8. References: <4eavds$d0u@news.cencom.net>
  9.     <ALUN.CHAMPION.96Jan29143951@g7240065.bridge.bst.bls.com>
  10.     <bredelin-3101961313580001@apm-b325-8.ucsd.edu>
  11. NNTP-Posting-Host: bstfirewall.bst.bls.com
  12. In-reply-to: bredelin@sdcc13.ucsd.edu's message of 31 Jan 1996 21:14:00 GMT
  13.  
  14. In article <bredelin-3101961313580001@apm-b325-8.ucsd.edu> bredelin@sdcc13.ucsd.edu (Benjamin Redelings) writes:
  15.  
  16. : I've been trying to find a read routine that doesn't block (i.e. wait to
  17. : return) until a carriage return is entered.  My program needs to
  18. : continuously process data, stopping periodically to process any input that
  19. : may have enterred the keyboard buffers since that last time it checked.
  20.  
  21. : A. On method would be the check the size of the keyboard buffer, called
  22. : cin.get() only if a complete line is present.  That would be optimal, and
  23. : would not involve any blocking.  However, whoever wrote iostream went to
  24. : great lengths to make sure that checking the size of cin's buffer is
  25. : really nasty.  I think I would have to write my own io library just to
  26. : check the size of the keyboard buffer!
  27.  
  28. Unfortunately this wont work, cin's buffer in no way reflects how many
  29. characters there are to read in the keyboard buffer.
  30.  
  31. : B. The other method would be to read all the input that is available, and
  32. : process if necessary.  However, if there is NO input, cin.get() WAITS for
  33. : a carriage return, which means that the user must press return every time
  34. : cin.get() is called to make the program keep processing.  That is
  35. : ridiculous.
  36.  
  37. : However, Alun Champion says
  38. : > 
  39. : > It is the host environment which line buffers.  
  40. : > In the UNIX environment you can use ioctl() calls to change the
  41. : > buffering characteristics of the terminal attached to cin, in other
  42. : > environments there may or may not be a mechanism by which you can
  43. : > inform the environment that line buffering is not to be performed.
  44. : > This is very dependent on the host environment, try a programmers
  45. : > newsgroup for the environment you are interested in.
  46. : > 
  47.  
  48. : Does anyone have more information?  How does one go about this, and what
  49. : might cin.get() be expected to return if it underflowed?
  50.  
  51. I would advise following my advice and try asking the question in the
  52. programmers newsgroup for the environment you are interested in.
  53. I can answer this question for the UNIX environment (though I don't peruse
  54. the Unix newsgroups (too much noise ;')), mail me if this is what you
  55. need.
  56.  
  57. Regards
  58.  
  59.   -A.
  60.  
  61. -- 
  62. | A.Champion                |
  63.